<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/index_work.css">
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.8.2.min.js"></script>

</head>
<body>
<table>
    <tr>
        <th colspan="10">
            <form action="list" method="post">
                请输入电影名字：<input type="text" name="aname" value="${aname}"/>
                <input type="submit" value="查询">
                <a href="add.jsp"><input type="button" value="添加"></a>
                <input type="button" value="批量删除" onclick="dels()">
            </form>
        </th>
    </tr>
<tr>
    <th>
        <input type="checkbox" class="c2" onclick="xx(event)">全选
    </th>
    <th>电影名称</th>
    <th>剧情介绍</th>
    <th>导演</th>
    <th>发行日期</th>
    <th>电影类型</th>
    <th>操作</th>
</tr>
    <c:forEach items="${plist.list}" var="y">
        <tr>
            <td>
                <input type="checkbox" class="c1" value="${y.yid}">
            </td>
            <td>${y.yname}</td>
            <td>${y.yinfo}</td>
            <td>${y.yren}</td>
            <td>${y.ydate}</td>
            <td>
                <c:forEach items="${y.listl}" var="l">
                    ${l.lname}
                </c:forEach>
            </td>
            <td><a href="update.jsp?yid=${y.yid}"><input type="button" value="修改"></a></td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="10">
            当前第${plist.pageNum}/${plist.pages}页，总共${plist.total}条记录
            <a href="list?pageNum=${plist.firstPage}"><input type="button" value="首页"></a>
            <a href="list?pageNum=${plist.prePage}"><input type="button" value="上一页"></a>
            <a href="list?pageNum=${plist.nextPage}"><input type="button" value="下一页"></a>
            <a href="list?pageNum=${plist.lastPage}"><input type="button" value="尾页"></a>
        </td>
    </tr>
</table>


<script type="text/javascript">

    function xx(event) {
        $(".c1").each(function () {
            this.checked=event.target.checked;
        })
    }

    function dels() {
        var ids="";
        $(".c1:checked").each(function () {
            ids+=","+$(this).val();
        })
        ids=ids.substring(1);
        if(ids==''){
            alert("请选择要删除的数据")
        }else {
            if (confirm("您确定删除吗？")) {
                $.post("dels", {"ids": ids}, function (num) {
                    if (num) {
                        alert("删除成功")
                        location = "list"
                    } else {
                        alert("删除失败")
                    }
                })
            }
        }
    }
</script>
</body>
</html>
